<?php

namespace backend\modules\goods\models;

use Yii;

/**
 * This is the model class for table "goods_desc_images".
 *
 * @property string $goods_desc_images_id
 * @property string $goods_id
 * @property string $goods_desc_image
 * @property integer $sort_number
 * @property integer $created_at
 * @property integer $type
 *
 * @property Goods $goods
 */
class GoodsDescImages extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'goods_desc_images';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
//            TimestampBehavior::className(),
            // 名为myBehavior4的行为，也是给出了MyBehavior类的配置数组
            'uuid' => [
                'class' => \common\behavior\uuidBehavior::className(),
                'owner' => $this
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['goods_desc_images_id','default','value'=>$this->getUUID()],
            [['goods_desc_images_id'], 'required'],
            [['sort_number','created_at','type'], 'integer'],
            [['goods_desc_images_id', 'goods_id'], 'string', 'max' => 40],
            [['goods_desc_image'], 'string', 'max' => 255],
            [['goods_id'], 'exist', 'skipOnError' => true, 'targetClass' => Goods::className(), 'targetAttribute' => ['goods_id' => 'goods_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'goods_desc_images_id' => Yii::t('app', 'Goods Desc Images ID'),
            'goods_id' => Yii::t('app', 'Goods ID'),
            'goods_desc_image' => Yii::t('app', 'Goods Image'),
            'sort_number' => Yii::t('app', 'Sort Number'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGoods()
    {
        return $this->hasOne(Goods::className(), ['goods_id' => 'goods_id']);
    }

    /**
     * @inheritdoc
     * @return \backend\modules\goods\models\query\GoodsGallImagesQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \backend\modules\goods\models\query\GoodsGallImagesQuery(get_called_class());
    }
}
